home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / misc / FetchRefs1.3.lha / FetchRefs1.3 / Source.lha / Source / GenerateIndex / GUI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-03-01  |  20.5 KB  |  911 lines

  1. #include "GenerateIndex.h"
  2.  
  3. extern struct TagItem MainOutline[], RefOutline[], OptionsOutline[], ScanStatOutline[];
  4. extern struct Library *TritonBase;
  5.  
  6. struct rtFileRequester *DataFileReq, *AddFileReq, *PrefsFileReq;
  7. struct TR_Project *MainPrj, *RefPrj, *OptionsPrj, *ScanStatPrj;
  8.  
  9. BOOL GoOn = TRUE, FileChanged;
  10.  
  11. /// About()
  12. void
  13. About(void)
  14. {
  15.      rtEZRequestTags("GenerateIndex " VERSION " (" DATE ")\n"
  16.              "Index file generator for FetchRefs\n"
  17.              "\n"
  18.              "By Anders Melchiorsen\n"
  19.              "\n"
  20.              "FreeWare, 1994-1996",
  21.  
  22.              "Okay",
  23.  
  24.              NULL, NULL,
  25.           
  26.              RTEZ_Flags, EZREQF_CENTERTEXT,
  27.              TAG_END,    NULL
  28.             );
  29. }
  30. ///
  31. /// OpenRefWindow()
  32. void
  33. OpenRefWindow(void)
  34. {
  35.     if (!RefPrj)
  36.     {
  37.     /* We call UpdateMain() because it also updates the text gadget
  38.      * with the file name of the ref window.
  39.      */
  40.     if (RefPrj = TR_OpenProject(Application, RefOutline))
  41.         UpdateMain();
  42.     } else
  43.     {
  44.     struct Window *win;
  45.  
  46.     /* Bring the ref window to the front */
  47.     if (win = TR_ObtainWindow(RefPrj))
  48.     {
  49.         WindowToFront(win);
  50.         ActivateWindow(win);
  51.         TR_ReleaseWindow(win);
  52.     }
  53.     }
  54. }
  55. ///
  56. /// OpenScanStatWindow()
  57. void
  58. OpenScanStatWindow(void)
  59. {
  60.     if (TritonBase)
  61.     ScanStatPrj = TR_OpenProject(Application, ScanStatOutline);
  62. }
  63. ///
  64. /// CloseScanStatWindow()
  65. void
  66. CloseScanStatWindow(void)
  67. {
  68.     if (ScanStatPrj)
  69.     TR_CloseProject(ScanStatPrj);
  70.     ScanStatPrj = NULL;
  71. }
  72. ///
  73.  
  74. /// GiveHelp() - open guide positioned at the help for <id>
  75. #include "HelpTable.h"
  76.  
  77. void
  78. GiveHelp(LONG id, struct Screen *scr)
  79. {
  80.     struct Library *AmigaGuideBase;
  81.     struct NewAmigaGuide nag = { NULL };
  82.     AMIGAGUIDECONTEXT handle;
  83.     LONG cnt;
  84.  
  85.     LockGUI();
  86.  
  87.     nag.nag_Name = "FetchRefs_GI.guide";
  88.     nag.nag_Screen = scr;
  89.  
  90.     for (cnt = 0; HelpTable[cnt].id; cnt++)
  91.     if (HelpTable[cnt].id == id)
  92.         break;
  93.     nag.nag_Node = HelpTable[cnt].node;
  94.     nag.nag_Line = HelpTable[cnt].line;
  95.  
  96.     /* Show the guide */
  97.     if (AmigaGuideBase = OpenLibrary("amigaguide.library", 34))
  98.     {
  99.     if (handle = OpenAmigaGuideA(&nag, NULL))
  100.         CloseAmigaGuide(handle);
  101.     else
  102.         PostMessage("Could not open guide");
  103.  
  104.     CloseLibrary(AmigaGuideBase);
  105.     } else
  106.     PostMessage("Could not open amigaguide.library v34+");
  107.  
  108.     UnlockGUI();
  109. }
  110. ///
  111. /// LockGUI()
  112. void
  113. LockGUI(void)
  114. {
  115.     TR_LockProject(MainPrj);
  116.     if (RefPrj)
  117.     TR_LockProject(RefPrj);
  118.     if (OptionsPrj)
  119.     TR_LockProject(OptionsPrj);
  120. }
  121. ///
  122. /// UnlockGUI()
  123. void
  124. UnlockGUI(void)
  125. {
  126.     TR_UnlockProject(MainPrj);
  127.     if (RefPrj)
  128.     TR_UnlockProject(RefPrj);
  129.     if (OptionsPrj)
  130.     TR_UnlockProject(OptionsPrj);
  131. }
  132. ///
  133.  
  134. /// AttachMainList()
  135. void
  136. AttachMainList(struct List *newlist)
  137. {
  138.     static struct List *lastlist = &FileList;
  139.  
  140.     if (!newlist)
  141.     newlist = lastlist;
  142.     else
  143.     lastlist = newlist;
  144.  
  145.     if (MainPrj)
  146.     {
  147.     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) newlist);
  148.  
  149.     if (newlist == &FileList)
  150.         UpdateMain();
  151.     }
  152. }
  153. ///
  154. /// DetachMainList()
  155. void
  156. DetachMainList(void)
  157. {
  158.     if (MainPrj)
  159.     TR_SetAttribute(MainPrj, MAIN_LIST_ID, NULL, (ULONG) ~0);
  160. }
  161. ///
  162. /// AttachRefList()
  163. void
  164. AttachRefList(void)
  165. {
  166.     struct FileEntry *f;
  167.  
  168.     if (RefPrj)
  169.     {
  170.     f = SelectedMain();
  171.     TR_SetAttribute(RefPrj, REF_LIST_ID, NULL, (ULONG) (f ? &f->RefsList : &EmptyList));
  172.     }
  173. }
  174. ///
  175. /// DetachRefList()
  176. void
  177. DetachRefList(void)
  178. {
  179.     if (RefPrj)
  180.     TR_SetAttribute(RefPrj, REF_LIST_ID, NULL, (ULONG) ~0);
  181. }
  182. ///
  183.  
  184. /// DeleteSelectedFile()
  185. void
  186. DeleteSelectedFile(void)
  187. {
  188.     struct FileEntry *f;
  189.  
  190.     if (f = SelectedMain())
  191.     {
  192.     DetachMainList();
  193.     FreeFile(f);
  194.     AttachMainList(NULL);
  195.     UpdateMain();
  196.  
  197.     FileChanged = TRUE;
  198.     }
  199. }
  200. ///
  201. /// DeleteSelectedReference()
  202. void
  203. DeleteSelectedReference(void)
  204. {
  205.     struct RefsEntry *r;
  206.  
  207.     if (r = SelectedRef())
  208.     {
  209.     FreeRef(r);
  210.     FileChanged = TRUE;
  211.     }
  212. }
  213. ///
  214. /// RescanAllFiles()
  215. void
  216. RescanAllFiles(void)
  217. {
  218.     struct Node *n, *next;
  219.  
  220.     for (next = GetHead(&FileList); n = next, next = next->ln_Succ; )
  221.     {
  222.     /* If the user break (window is closed) the list is not sorted
  223.      * so we do that before returning.
  224.      */
  225.     if (!ScanStatPrj)
  226.     {
  227.         SortExecList(&FileList, SortCompareFunc, NULL);
  228.         break;
  229.     }
  230.  
  231.     /* Rescan this one. This may delete the entry, so we have cached
  232.      * a pointer to the next.
  233.      */
  234.     IndexFile("", n->ln_Name);
  235.     }
  236. }
  237. ///
  238.  
  239. /// UpdateMain()
  240. void
  241. UpdateMain(void)
  242. {
  243.     struct FileEntry *n = SelectedMain();
  244.  
  245.     /* Update main windows action gadgets: no list, no action */
  246.     TR_SetAttribute(MainPrj, MAIN_DELETE_ID, TRAT_Disabled, !n);
  247.     TR_SetAttribute(MainPrj, MAIN_RESCAN_ID, TRAT_Disabled, !n);
  248.     TR_SetAttribute(MainPrj, MAIN_RESCANALL_ID, TRAT_Disabled, !n);
  249.  
  250.     /* Update main 'references count' gadget */
  251.     TR_SetAttribute(MainPrj, MAIN_REFERENCES_ID, TRAT_Value, n ? NumOfNodes(&n->RefsList) : 0);
  252.  
  253.     /* Update ref 'file' gadget */
  254.     if (RefPrj)
  255.     {
  256.     TR_SetAttribute(RefPrj, REF_FILE_ID, TRAT_Text, (ULONG) (n ? (STRPTR)n->Name : (STRPTR)""));
  257.     UpdateRef();
  258.     }
  259. }
  260. ///
  261. /// UpdateRef()
  262. void
  263. UpdateRef(void)
  264. {
  265.     static struct FileEntry *shown = (APTR)-1;
  266.     
  267.     if (RefPrj)
  268.     {
  269.     struct FileEntry *f = SelectedMain();
  270.     struct RefsEntry *r = SelectedRef();
  271.  
  272.     /* Update ref window 'delete' gadget */
  273.     TR_SetAttribute(RefPrj, REF_DELETE_ID, TRAT_Disabled, !r);
  274.     
  275.     /* Update ref window's listview if main window is changed */
  276.     if (f != shown)
  277.     {
  278.         TR_SetAttribute(RefPrj, REF_LIST_ID, TRAT_Value, 0);
  279.         TR_SetAttribute(RefPrj, REF_LIST_ID, NULL, (ULONG) (f ? &f->RefsList : &EmptyList));
  280.     }
  281.  
  282.     /* Update ref windows information gadgets */
  283.     TR_SetAttribute(RefPrj, REF_OFFSET_ID, TRAT_Value, r ? r->Offset : 0);
  284.     TR_SetAttribute(RefPrj, REF_LENGTH_ID, TRAT_Value, r ? r->Length : 0);
  285.     TR_SetAttribute(RefPrj, REF_GOTO_ID, TRAT_Value, r ? r->Goto : 0);
  286.  
  287.     shown = f;
  288.     } else
  289.     shown = (APTR)-1;
  290. }
  291. ///
  292. /// UpdateOptions()
  293. void
  294. UpdateOptions(void)
  295. {
  296.     TR_SetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID,          TRAT_Value, Settings.AutoDocPrf.Active);
  297.  
  298.     TR_SetAttribute(OptionsPrj, OPTIONS_C_ID,                TRAT_Value, Settings.CPrf.Active);
  299.     TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,         TRAT_Value, Settings.CPrf.Define);
  300.     TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,         TRAT_Value, Settings.CPrf.Struct);
  301.     TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,        TRAT_Value, Settings.CPrf.Typedef);
  302.  
  303.     TR_SetAttribute(OptionsPrj, OPTIONS_E_ID,                TRAT_Value, Settings.EPrf.Active);
  304.     TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,          TRAT_Value, Settings.EPrf.Const);
  305.     TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,         TRAT_Value, Settings.EPrf.Object);
  306.     TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,           TRAT_Value, Settings.EPrf.Proc);
  307.  
  308.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_ID,              TRAT_Value, Settings.AsmPrf.Active);
  309.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,          TRAT_Value, Settings.AsmPrf.Equ);
  310.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,    TRAT_Value, Settings.AsmPrf.Structure);
  311.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,        TRAT_Value, Settings.AsmPrf.Macro);
  312.  
  313.     TR_SetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID,      TRAT_Value, Settings.Recursively);
  314.     TR_SetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID,        TRAT_Value, Settings.KeepEmpty);
  315.     TR_SetAttribute(OptionsPrj, OPTIONS_UNKNOWNASAUTODOC_ID, TRAT_Value, Settings.UnknownAsAutoDoc);
  316.  
  317.     UpdateOptionsGhost();
  318. }
  319. ///
  320. /// UpdateOptionsGhost()
  321. void
  322. UpdateOptionsGhost(void)
  323. {
  324.     LONG ghost;
  325.  
  326.     if (!OptionsPrj)
  327.     return;
  328.     
  329.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_C_ID, TRAT_Value);
  330.     TR_SetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,        TRAT_Disabled, ghost);
  331.     TR_SetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,        TRAT_Disabled, ghost);
  332.     TR_SetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,       TRAT_Disabled, ghost);
  333.  
  334.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_E_ID, TRAT_Value);
  335.     TR_SetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,         TRAT_Disabled, ghost);
  336.     TR_SetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,        TRAT_Disabled, ghost);
  337.     TR_SetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,          TRAT_Disabled, ghost);
  338.  
  339.     ghost = !TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID, TRAT_Value);
  340.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,         TRAT_Disabled, ghost);
  341.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,   TRAT_Disabled, ghost);
  342.     TR_SetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,       TRAT_Disabled, ghost);
  343. }
  344. ///
  345. /// UpdateSettingsStruct()
  346. void
  347. UpdateSettingsStruct(void)
  348. {
  349.     Settings.AutoDocPrf.Active  = TR_GetAttribute(OptionsPrj, OPTIONS_AUTODOC_ID,          TRAT_Value);
  350.  
  351.     Settings.CPrf.Active        = TR_GetAttribute(OptionsPrj, OPTIONS_C_ID,                TRAT_Value);
  352.     Settings.CPrf.Define        = TR_GetAttribute(OptionsPrj, OPTIONS_C_DEFINE_ID,         TRAT_Value);
  353.     Settings.CPrf.Struct        = TR_GetAttribute(OptionsPrj, OPTIONS_C_STRUCT_ID,         TRAT_Value);
  354.     Settings.CPrf.Typedef       = TR_GetAttribute(OptionsPrj, OPTIONS_C_TYPEDEF_ID,        TRAT_Value);
  355.  
  356.     Settings.EPrf.Active        = TR_GetAttribute(OptionsPrj, OPTIONS_E_ID,                TRAT_Value);
  357.     Settings.EPrf.Const         = TR_GetAttribute(OptionsPrj, OPTIONS_E_CONST_ID,          TRAT_Value);
  358.     Settings.EPrf.Object        = TR_GetAttribute(OptionsPrj, OPTIONS_E_OBJECT_ID,         TRAT_Value);
  359.     Settings.EPrf.Proc          = TR_GetAttribute(OptionsPrj, OPTIONS_E_PROC_ID,           TRAT_Value);
  360.  
  361.     Settings.AsmPrf.Active      = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_ID,              TRAT_Value);
  362.     Settings.AsmPrf.Equ         = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_EQU_ID,          TRAT_Value);
  363.     Settings.AsmPrf.Structure   = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_STRUCTURE_ID,    TRAT_Value);
  364.     Settings.AsmPrf.Macro       = TR_GetAttribute(OptionsPrj, OPTIONS_ASM_MACRO_ID,        TRAT_Value);
  365.  
  366.     Settings.Recursively        = TR_GetAttribute(OptionsPrj, OPTIONS_RECURSIVELY_ID,      TRAT_Value);
  367.     Settings.KeepEmpty          = TR_GetAttribute(OptionsPrj, OPTIONS_KEEPEMPTY_ID,        TRAT_Value);
  368.     Settings.UnknownAsAutoDoc   = TR_GetAttribute(OptionsPrj, OPTIONS_UNKNOWNASAUTODOC_ID, TRAT_Value);
  369. }
  370. ///
  371.  
  372. /// HandleGUI()
  373. void
  374. HandleGUI(void)
  375. {
  376.     struct TR_Message *msg;
  377.  
  378.     if (!TritonBase)
  379.     return;
  380.  
  381.     while (msg = TR_GetMsg(Application))
  382.     {
  383.     if (msg->trm_Class == TRMS_HELP)
  384.     {
  385.         struct Window *win;
  386.         struct Screen *scr;
  387.  
  388.         if (win = TR_ObtainWindow(MainPrj))
  389.         {
  390.         scr = win->WScreen;
  391.         TR_ReleaseWindow(win);
  392.         } else
  393.         scr = NULL;
  394.  
  395.         GiveHelp(msg->trm_ID, scr);
  396.     }
  397.     else
  398.     {
  399.         if (msg->trm_Class == TRMS_NEWVALUE)
  400.         HandleListViewClick(msg);
  401.  
  402.         if (msg->trm_Project == MainPrj)
  403.         HandleMainIDCMP(msg);
  404.         else if (msg->trm_Project == RefPrj)
  405.         HandleRefIDCMP(msg);
  406.         else if (msg->trm_Project == OptionsPrj)
  407.         HandleOptionsIDCMP(msg);
  408.         else if (msg->trm_Project == ScanStatPrj)
  409.         HandleScanStatIDCMP(msg);
  410.     }
  411.  
  412.     TR_ReplyMsg(msg);
  413.     }
  414.  
  415.     /* Make sure that the user wants to quit */
  416.     if ((!GoOn) && (FileChanged))
  417.     {
  418.     if (!rtEZRequestTags("There are changes!\nReally quit?",
  419.                 "_Okay|_Cancel",
  420.                 NULL, NULL,
  421.  
  422.                 RT_Underscore, '_',
  423.                 TAG_END))
  424.         GoOn = TRUE;
  425.     }
  426. }
  427. ///
  428. /// HandleListViewClick()
  429. void
  430. HandleListViewClick(struct TR_Message *m)
  431. {
  432.     if (m->trm_Project == MainPrj)
  433.     {
  434.     UpdateMain();
  435.     if (m->trm_Qualifier & IEQUALIFIER_REPEAT)
  436.         OpenRefWindow();
  437.     }
  438.     else if (m->trm_Project == RefPrj)
  439.     UpdateRef();
  440. }
  441. ///
  442. /// HandleMenu()
  443. void
  444. HandleMenu(struct TR_Message *m)
  445. {
  446.     switch (m->trm_ID)
  447.     {
  448.     case MAIN_MENU_PROJECT_CLEAR:
  449.         LockGUI();
  450.         if ((!FileChanged) || rtEZRequestTags("There are changes!\nReally clear the entire list?",
  451.                 "_Okay|_Cancel",
  452.                 NULL, NULL,
  453.                     
  454.                 RT_Underscore, '_',
  455.                 TAG_END))
  456.         {
  457.         InitializeFileList();
  458.         UpdateMain();
  459.  
  460.         FileChanged = FALSE;
  461.         }
  462.         UnlockGUI();
  463.     break;
  464.  
  465.     case MAIN_MENU_PROJECT_LOAD:
  466.         LockGUI();
  467.  
  468.         if ((!FileChanged) || rtEZRequestTags("There are changes!\nReally load a new file?",
  469.                 "_Okay|_Cancel",
  470.                 NULL, NULL,
  471.  
  472.                 RT_Underscore, '_',
  473.                 TAG_END))
  474.         {
  475.         if (!IsListEmpty(&FileList))
  476.         {
  477.             ULONG ret;
  478.  
  479.             ret = rtEZRequestTags(  "Current list is not empty!",
  480.                         "_Replace|_Append|_Cancel",
  481.                         NULL, NULL,
  482.                         
  483.                         RT_Underscore, '_',
  484.                         TAG_END);
  485.  
  486.             if (ret == 0)
  487.             {
  488.             UnlockGUI();
  489.             break;
  490.             }
  491.  
  492.             if (ret == 1)
  493.             {
  494.             InitializeFileList();
  495.             UpdateMain();
  496.  
  497.             FileChanged = FALSE;
  498.             }
  499.  
  500.             if (ret == 2)
  501.             FileChanged = TRUE;
  502.         } else
  503.             FileChanged = FALSE;
  504.  
  505.         LoadData(NULL);
  506.         UpdateMain();
  507.         }
  508.  
  509.         UnlockGUI();
  510.     break;
  511.  
  512.     case MAIN_MENU_PROJECT_SAVE:
  513.         LockGUI();
  514.         SaveData(NULL);
  515.         UnlockGUI();
  516.     break;
  517.  
  518.     case MAIN_MENU_PROJECT_ABOUT:
  519.         LockGUI();
  520.         About();
  521.         UnlockGUI();
  522.     break;
  523.  
  524.     case MAIN_MENU_PROJECT_QUIT:
  525.         GoOn = FALSE;
  526.     break;
  527.     }
  528. }
  529. ///
  530. /// HandleMainIDCMP()
  531. void
  532. HandleMainIDCMP(struct TR_Message *m)
  533. {
  534.     if (m->trm_Class == TRMS_CLOSEWINDOW)
  535.     {
  536.     GoOn = FALSE;
  537.     return;
  538.     }
  539.     
  540.     HandleMenu(m);
  541.  
  542.     /* Check for gadgets */
  543.     switch (m->trm_ID)
  544.     {
  545.     case MAIN_OPENREFWINDOW_ID:
  546.         OpenRefWindow();
  547.     break;
  548.  
  549.     case MAIN_SCAN_ID:
  550.         struct rtFileList *selfiles;
  551.         char tmpname[108];
  552.  
  553.         LockGUI();
  554.  
  555.         if (selfiles = rtFileRequest(AddFileReq, tmpname,
  556.                   "Select files to index...",
  557.  
  558.                   RTFI_Flags,    FREQF_MULTISELECT | FREQF_SELECTDIRS | FREQF_PATGAD,
  559.                   TAG_END))
  560.         {
  561.         StartScanning();
  562.         IndexFileList(AddFileReq->Dir, selfiles);
  563.         rtFreeFileList(selfiles);
  564.         SortExecList(&FileList, SortCompareFunc, NULL);
  565.         StopScanning(FALSE);
  566.         }
  567.  
  568.         UnlockGUI();
  569.     break;
  570.     
  571.     case MAIN_DELETE_ID:
  572.         DeleteSelectedFile();
  573.     break;
  574.  
  575.     case MAIN_OPTIONS_ID:
  576.         if (!OptionsPrj)
  577.         {
  578.         TR_SetAttribute(MainPrj, MAIN_SCAN_ID, TRAT_Disabled, TRUE);
  579.         if (OptionsPrj = TR_OpenProject(Application, OptionsOutline))
  580.             UpdateOptions();
  581.         else
  582.             TR_SetAttribute(MainPrj, MAIN_SCAN_ID, TRAT_Disabled, FALSE);
  583.         } else
  584.         {
  585.         struct Window *win;
  586.  
  587.         /* Bring the options window to the front */
  588.         if (win = TR_ObtainWindow(OptionsPrj))
  589.         {
  590.             WindowToFront(win);
  591.             ActivateWindow(win);
  592.             TR_ReleaseWindow(win);
  593.         }
  594.         }
  595.     break;
  596.  
  597.     case MAIN_RESCAN_ID:
  598.     {
  599.         struct FileEntry *f;
  600.  
  601.         if (f = SelectedMain())
  602.         {
  603.         StartScanning();
  604.         LockGUI();
  605.  
  606.         /* Rescan. This will free the old references */
  607.         IndexFile("", f->Name);
  608.  
  609.         UnlockGUI();
  610.         StopScanning(FALSE);
  611.         }
  612.     }
  613.     break;
  614.  
  615.     case MAIN_RESCANALL_ID:
  616.         StartScanning();
  617.         LockGUI();
  618.  
  619.         RescanAllFiles();
  620.  
  621.         UnlockGUI();
  622.         StopScanning(FALSE);
  623.     break;
  624.     }
  625. }
  626. ///
  627. /// HandleRefIDCMP()
  628. void
  629. HandleRefIDCMP(struct TR_Message *m)
  630. {
  631.     if (m->trm_Class == TRMS_CLOSEWINDOW)
  632.     {
  633.     TR_CloseProject(RefPrj);
  634.     RefPrj = NULL;
  635.     } else if (m->trm_Class == TRMS_ACTION)
  636.     {
  637.     if (m->trm_ID == REF_DELETE_ID)
  638.     {
  639.         DeleteSelectedReference();
  640.         UpdateMain();
  641.     }
  642.     }
  643. }
  644. ///
  645. /// HandleOptionsIDCMP()
  646. void
  647. HandleOptionsIDCMP(struct TR_Message *m)
  648. {
  649.     static UBYTE prefname[108];
  650.  
  651.     if ((m->trm_Class == TRMS_CLOSEWINDOW) || (m->trm_Class == TRMS_ACTION && m->trm_ID == OPTIONS_CANCEL_ID))
  652.     {
  653.     TR_CloseProject(OptionsPrj);
  654.     OptionsPrj = NULL;
  655.     TR_SetAttribute(MainPrj, MAIN_SCAN_ID, TRAT_Disabled, FALSE);
  656.     }
  657.  
  658.     if (m->trm_Class == TRMS_ACTION)
  659.     {
  660.     if ((m->trm_ID == OPTIONS_USE_ID) || (m->trm_ID == OPTIONS_SAVE_ID))
  661.     {
  662.         UpdateSettingsStruct();
  663.  
  664.         if (m->trm_ID == OPTIONS_SAVE_ID)
  665.         SaveSettings("ENVARC:FetchRefs_GI.prefs");
  666.         SaveSettings("ENV:FetchRefs_GI.prefs");
  667.  
  668.         TR_CloseProject(OptionsPrj);
  669.         OptionsPrj = NULL;
  670.         TR_SetAttribute(MainPrj, MAIN_SCAN_ID, TRAT_Disabled, FALSE);
  671.     }
  672.  
  673.     if (m->trm_ID == OPTIONS_MENU_PROJECT_OPEN_ID)
  674.     {
  675.         if (rtFileRequest(PrefsFileReq, prefname,
  676.                   "Load settings...",
  677.  
  678.                   TAG_END))
  679.         {
  680.         BPTR newdir, olddir;
  681.         
  682.         if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
  683.         {
  684.             struct Prefs tmpsettings;
  685.  
  686.             /* We copy to 'tmpsettings' to be able to restore the
  687.              * original settings if Cancel is chosen. By using a
  688.              * temporary variable only the state of the gadgets
  689.              * is changed. The change is not permanent until Use
  690.              * or Save is chosen.
  691.              */
  692.             CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
  693.             olddir = CurrentDir(newdir);
  694.             LoadSettings(prefname);
  695.             CurrentDir(olddir);
  696.             UnLock(newdir);
  697.             UpdateOptions();
  698.             CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
  699.         }
  700.         }
  701.     }
  702.     
  703.     if (m->trm_ID == OPTIONS_MENU_PROJECT_SAVEAS_ID)
  704.     {
  705.         if (rtFileRequest(PrefsFileReq, prefname,
  706.                   "Save settings...",
  707.  
  708.                   RTFI_Flags,    FREQF_SAVE,
  709.                   TAG_END))
  710.         {
  711.         BPTR newdir, olddir;
  712.         
  713.         if (newdir = Lock(PrefsFileReq->Dir, SHARED_LOCK))
  714.         {
  715.             struct Prefs tmpsettings;
  716.  
  717.             /* As SaveSettings() uses the 'Settings' struct we
  718.              * need to fill it with the current settings even
  719.              * though they may still be Cancel'ed. Therefore we
  720.              * copy the original back.
  721.              */
  722.             CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
  723.             UpdateSettingsStruct();
  724.             olddir = CurrentDir(newdir);
  725.             SaveSettings(prefname);
  726.             CurrentDir(olddir);
  727.             UnLock(newdir);
  728.             CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
  729.         }
  730.         }
  731.     }
  732.  
  733.     if (m->trm_ID == OPTIONS_MENU_PROJECT_LASTSAVED_ID)
  734.     {
  735.         struct Prefs tmpsettings;
  736.  
  737.         /* We copy to 'tmpsettings' to be able to restore the
  738.          * original settings if Cancel is chosen.
  739.          */
  740.         CopyMem(&Settings, &tmpsettings, sizeof(struct Prefs));
  741.         LoadSettings("ENVARC:FetchRefs_GI.prefs");
  742.         UpdateOptions();
  743.         CopyMem(&tmpsettings, &Settings, sizeof(struct Prefs));
  744.     }
  745.     }
  746.  
  747.     if (m->trm_Class = TRMS_NEWVALUE)
  748.     {
  749.     if (m->trm_ID == OPTIONS_AUTODOC_ID || m->trm_ID == OPTIONS_C_ID ||
  750.         m->trm_ID == OPTIONS_E_ID || m->trm_ID == OPTIONS_ASM_ID)
  751.         UpdateOptionsGhost();
  752.     }
  753. }
  754. ///
  755. /// HandleScanStatIDCMP()
  756. void
  757. HandleScanStatIDCMP(struct TR_Message *m)
  758. {
  759.     if ((m->trm_Class == TRMS_CLOSEWINDOW) || (m->trm_Class == TRMS_ACTION && m->trm_ID == SCANSTAT_STOP_ID))
  760.     StopScanning(TRUE);
  761. }
  762. ///
  763.  
  764. /// NumOfNodes()
  765. ULONG
  766. NumOfNodes(struct List *l)
  767. {
  768.     struct Node *n = GetHead(l);
  769.     ULONG cnt = 0;
  770.  
  771.     while (n->ln_Succ)
  772.     {
  773.     cnt++;
  774.     n = n->ln_Succ;
  775.     }
  776.  
  777.     return(cnt);
  778. }
  779. ///
  780. /// SelectedMain()
  781. struct FileEntry *
  782. SelectedMain(void)
  783. {
  784.     struct FileEntry *f;
  785.  
  786.     /* Find pointer to selected node in main listview */
  787.     if (IsListEmpty(&FileList))
  788.     f = NULL;
  789.     else
  790.     {
  791.     ULONG cnt;
  792.     
  793.     f = (struct FileEntry *)GetHead(&FileList);
  794.     cnt = TR_GetAttribute(MainPrj, MAIN_LIST_ID, TRAT_Value);
  795.     while (cnt--)
  796.         f = f->node.ln_Succ;
  797.     }
  798.     return(f);
  799. }
  800. ///
  801. /// SelectedRef()
  802. struct RefsEntry *
  803. SelectedRef(void)
  804. {
  805.     struct FileEntry *f = SelectedMain();
  806.     struct RefsEntry *r;
  807.  
  808.     /* Find pointer to selected node in main listview */
  809.     if ((f == NULL) || (IsListEmpty(&f->RefsList)))
  810.     r = NULL;
  811.     else
  812.     {
  813.     ULONG cnt;
  814.     
  815.     r = (struct RefsEntry *)GetHead(&f->RefsList);
  816.     cnt = TR_GetAttribute(RefPrj, REF_LIST_ID, TRAT_Value);
  817.     while (cnt--)
  818.         r = r->node.ln_Succ;
  819.     }
  820.     return(r);
  821. }
  822. ///
  823.  
  824. /// GoGUI()
  825. void
  826. GoGUI(void)
  827. {
  828.     if (!ReqToolsBase)
  829.     CloseGUI();
  830.     
  831.     if (!TR_OpenTriton(TRITON14VERSION,
  832.         TRCA_Name,      "GenerateIndex",
  833.         TRCA_LongName,  "FetchRefs' GenerateIndex",
  834.         TRCA_Info,      "Index file generator for FetchRefs",
  835.         TRCA_Version,   VERSION,
  836.         TRCA_Release,   RELEASE,
  837.         TRCA_Date,      DATE,
  838.         TAG_END))
  839.     CloseGUI();
  840.  
  841.     if (!(DataFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  842.     CloseGUI();
  843.  
  844.     if (!(AddFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  845.     CloseGUI();
  846.     rtChangeReqAttr(AddFileReq, RTFI_MatchPat, "~(#?.(guide|a|c|e|o))", TAG_END);
  847.  
  848.     if (!(PrefsFileReq = rtAllocRequestA(RT_FILEREQ, NULL)))
  849.     CloseGUI();
  850.  
  851.     /* Load a data file if any is specified by tool types/Shell arguments */
  852.     if (DataName[0])
  853.     {
  854.     STRPTR p;
  855.  
  856.     LoadData(DataName);
  857.     p = PathPart(DataName);
  858.  
  859.     /* If a path is specified we split up in path and file name */
  860.     if (p != DataName)
  861.     {
  862.         UBYTE c;
  863.  
  864.         c = *p;
  865.         *p = 0;
  866.         rtChangeReqAttr(DataFileReq, RTFI_Dir, DataName, TAG_END);
  867.         *p = c;
  868.         strcpy(DataName, FilePart(DataName));
  869.     }
  870.     }
  871.  
  872.     if (!(MainPrj = TR_OpenProject(Application, MainOutline)))
  873.     CloseGUI();
  874.  
  875.     UpdateMain();
  876.  
  877.     while (GoOn)
  878.     {
  879.     TR_Wait(Application, NULL);
  880.     HandleGUI();
  881.     }
  882.  
  883.     CloseGUI();
  884. }
  885. ///
  886. /// CloseGUI()
  887. void
  888. CloseGUI(void)
  889. {
  890.     if (ReqToolsBase)
  891.     {
  892.     rtFreeRequest(DataFileReq);
  893.     rtFreeRequest(AddFileReq);
  894.     rtFreeRequest(PrefsFileReq);
  895.     } else
  896.     CloseAll(ERROR_CUSTOM, "You need ReqTools version 38+ for the GUI!");
  897.  
  898.     if (TritonBase)
  899.     {
  900.     if (MainPrj)
  901.         TR_CloseProject(MainPrj);
  902.     if (RefPrj)
  903.         TR_CloseProject(RefPrj);
  904.     if (OptionsPrj)
  905.         TR_CloseProject(OptionsPrj);
  906.     TR_CloseTriton();
  907.     } else
  908.     CloseAll(ERROR_CUSTOM, "You need Triton version 5+!");
  909. }
  910. ///
  911.